<?php if(!empty ($companies)){ ?>
<div class="products form">
<?php echo $this->Form->create('Product', array('action' => 'addNewProduct', 'id' => 'formAddNewProduct', 'type' => 'file'));?>
	<fieldset>
 		<legend><?php __('Add New Product') ?></legend>
	<?php
                
		echo $this->Form->input('company_id', array( 'label' => 'Company:'));
		echo $this->Form->input('name', array('label' => 'Product Name:<em class="required_field">(required)</em><em id="product_name_note"></em>', 'id' => 'product_name'));
                echo $this->Html->tag('div',$this->Html->tag('label', __('Product image', true), array('for' => 'product_name')).$this->Form->file('product_image', array('id' =>'product_name')));
		echo $this->Form->input('description', array( 'label' => 'Description:'));
                echo '<br/>';
                echo $this->Form->button(__('Add Product', true), array('type' => 'button','class' => 'sexy_button', 'id' => 'add_product') );
	?>
	</fieldset>
<?php echo $this->Form->end();?>
</div>
<?php
    $this->Js->get('#add_product');
    $this->Js->event('click', 'submitProduct()');

    $this->Js->get('#product_name');
    $this->Js->event('blur', 'checkFieldValue("#product_name")');
?>
<script type="text/javascript">
    function submitProduct(){
        var name = $('#product_name').val();
        if(name.length < 1){
            $('#product_name_note').removeClass('feedback_correct');
            $('#product_name_note').addClass('feedback_error');
            $('#product_name_note').html('<?php __('Please provide product name field.') ?>');
        }else{
            $('#formAddNewProduct').submit();
        }
    }
    function checkFieldValue(elementId){
        var val = $(elementId).val();
        if(val.length < 1){
           $('#product_name_note').removeClass('feedback_correct');
           $('#product_name_note').addClass('feedback_error');
           $('#product_name_note').html('<?php __('Please provide product name field.') ?>');
        }else{
            $('#product_name_note').removeClass('feedback_error');
            $('#product_name_note').html('');
        }
    }
</script>
<?php }else{ ?>
<div id="message_notice" class="message_box">
    <em class="message_error">
        <?php echo sprintf(__('No company selected. Please setup new company first before add new product. %s', true), $this->Html->link(__('Add a new company', true), array('controller' => 'company', 'action' => 'setup_company'))); ?>
    </em>
</div>
<?php } ?>